﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 默写
{
    public partial class NewCharsFrm : Form
    {
        private const string defaulttext = "例(写/认：太：太阳；太太；太平；太空)";

        public NewCharsFrm()
        {
            InitializeComponent();
            this.CancelButton = button2;
            //this.AcceptButton = button1;
            richTextBox1.Text = defaulttext;
        }

        private void richTextBox1_Leave(object sender, EventArgs e)
        {
            if (richTextBox1.Text.Length == 0)
            {
                richTextBox1.ForeColor = Color.Gray;
                richTextBox1.Text = defaulttext;
            }
        }

        private void richTextBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (richTextBox1.SelectedText.Length <= 0 && richTextBox1.ForeColor == Color.Gray)
            {
                richTextBox1.SelectAll();
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (richTextBox1.ForeColor == Color.Gray)
            {
                richTextBox1.ForeColor = Color.Black;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (richTextBox1.ForeColor == Color.Gray)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
            if (ValidateString.ValidateCharString(richTextBox1))
            {
                //button1.DialogResult = DialogResult.OK;
                this.DialogResult = DialogResult.OK;
                this.Close();

            }
        }

        public string Characters
        {
            get
            {
                if (richTextBox1.ForeColor == Color.Black)
                {
                    return richTextBox1.Text;
                }
                else
                {
                    return "";
                }

            }
        }

    }
}
